const Router = require('koa-router')
const Category = require('../dbs/models/category')

const router = new Router({ prefix: '/category' })

router.get('/crumbs', async (ctx) => {
  const city = ctx.query.city ? ctx.query.city.replace('市', '') : '北京'
  const result = await Category.findOne({ city })
  if (result) {
    ctx.body = {
      areas: result.areas,
      types: result.types
    }
  } else {
    ctx.body = {
      city,
      areas: [],
      types: []
    }
  }
})

// export default router
module.exports = router
